package com.example.common.presenter;

import com.example.common.model.JavaCourseModel;
import com.example.common.slice.DetailAbilitySlice;
import com.example.common.model.bean.JavaCourse;
import com.example.commonlib.base.presenter.SuperPresenter;
import com.example.commonlib.net.ServiceResponse;
import ohos.aafwk.content.Intent;
import org.jetbrains.annotations.Nullable;

public class DetailAbilityPresenter extends SuperPresenter<DetailAbilitySlice> {
    private int mUnit = 1;
    private int mPage = 0;
//    private String[] mTitles = {"第一章", "第二章", "第三章", "第四章", "第五章", "第六章", "第七章", "第八章", "第九章", "第十章"};


    @Override
    public void onCreate(@Nullable Intent intent) {
        getData(true);
    }

    public void getData(final boolean isRefresh) {

        if (isRefresh) {
            mPage = 0;
        } else {
            mPage++;
        }
        JavaCourseModel.getInstance().getJavaCourseFromDir(mUnit, mPage, new ServiceResponse<JavaCourse[]>() {
            @Override
            public void onNext(JavaCourse[] javaCourses) {
                super.onNext(javaCourses);
                getView().showLoading();
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                getView().showError();
            }
        });
    }
}
